package com.wt.struggle.goodbye.main.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.ProBaseAdapter
import com.wt.struggle.goodbye.info.MessageInfo
import com.wt.struggle.goodbye.info.NewsInfo
import kotlinx.android.synthetic.main.text_item_layout.view.*

class TextAdapter(context: Context, val parendInfo: NewsInfo, list: ArrayList<MessageInfo>) :
    ProBaseAdapter<MessageInfo>(context, list) {

    override fun onCreateView(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return VH(inflater.inflate(R.layout.text_item_layout, parent, false))
    }

    override fun onUpdateHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>) {

    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val info = list[position]
        val vh = holder as VH
        vh.commentItem.text =
                "${info.appUserExtraInfo!!.nickName} 回复 ${parendInfo.appUserExtraInfo!!.nickName}: ${info.content}"

        val threeArr = info.subCommentInfoList

        val sb = StringBuilder()

        if (threeArr != null && threeArr.size != 0) {

            vh.tvThreeText.visibility = View.VISIBLE

            for (temp in threeArr) {
                sb.append("${temp.appUserExtraInfo!!.nickName} 回复 ${info.appUserExtraInfo!!.nickName}: ${temp.content}")
                    .append("\n")
            }
        } else {
            vh.tvThreeText.visibility = View.GONE
        }

        vh.tvThreeText.text = sb.toString()


    }

    inner class VH(view: View) : RecyclerView.ViewHolder(view) {
        val commentItem = view.commentItem
        val tvThreeText = view.tvThreeText

    }
}